#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int findLengthOfShortestSubarray(vector<int>& arr) {
        int n=arr.size(),right=n-1;
        while(right>0&&arr[right-1]<=arr[right])
            right--;
        if(right==0)return 0;
        int ans=right;
        for(int left=0;left<n;left++)
        {
            while(right<n&&arr[right]<arr[left])
            {
                right++;
            }
                ans=min(ans,right-left-1);
                if(left+1<n&&arr[left]>arr[left+1])return ans;

            
        }
        return ans;
    }
};